﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true"
    CodeBehind="news-add.aspx.cs" Inherits="VQWEB.administrator.news.news_add" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
   <form id="frmObjects" action="" method="post">
    <div id="col8" class="col-md-8"></div>
    <div id="col4" class="col-md-4">
    </div>
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/news/handler";
        var url_input = '<%=ResolveUrl("~/administrator/templates/input.tpl") %>';

        $(document).ready(function () {
            $.get(url_ashx, { view_news: "view_news", Id: GetId() }, function (data) {
                var parse = $.parseJSON(data);
                var category = parse.category;
                var tag = parse.tag;
                var array_category, array_tag;
               if (CheckAtionInPath("add")) {
                    array_category = array_checkbox(category);
                    array_tag = array_checkbox(tag);
                    loadform(0, "", "", "", "", 0,"", false, false, array_category, array_tag);
                }
                else if (CheckAtionInPath("edit")) {
                    var news = parse.news;
                    array_category = array_checkbox(category);
                    array_tag = array_checkbox(tag);
                    loadform(news.id, news.title, news.image, news.description, news.content, news.hit, news.date, news.ishome, news.active, array_category, array_tag);

                }

            });
        });
        function loadform(id, title,image,description, content, hit, date,ishome, active, array_category,array_tag) {
            $.jqoteload(url_input, function (tmpl) {
                $("#col4").multiple("groupcheckbox", null, array_category, "Category:", tmpl.input_tpl);
                $("#col4").multiple("groupcheckbox", null, array_tag, "Tag:", tmpl.input_tpl);
                $("#col8").single("hidden", "news_id", id, null, null, tmpl.input_tpl);
                $("#col8").single("text", "news_title", title, "Tiêu đề:", null, tmpl.input_tpl);
                $("#col8").single("textarea", "news_description", description, "Trích dẫn:", null, tmpl.input_tpl);
                $("#col8").single("editor", "news_content", content, "Nội dung:", null, tmpl.input_tpl);
                $("#col8").single("text", "news_hit", hit, "Lượt xe:", null, tmpl.input_tpl);
                $("#col8").single("text", "news_date", date, "Ngày đăng:", null, tmpl.input_tpl);
                $("#col8").single("checkbox", "news_ishome", true, "Vị trí:", ishome, tmpl.input_tpl);
                $("#col8").single("checkbox", "news_active", true, "Kich hoat", active, tmpl.input_tpl);
                tinymce.init({ selector: 'textarea#tinymce' });
                $("#frmObjects").validate({
                    rules: { news_title: { required: true} },
                    messages: { news_title: { required: null} }
                });
                $("input[name='news_date']").mask("99/99/9999");
            });

        }


        $(document).on("click", "#btnCancel", function () {
            window.location = "/admin/news/list";
        });
        $(document).on("click", "#btnSave", function () {
            if ($("#frmObjects").valid()) {
                var value = tinymce.get('tinymce').getContent();
                $("textarea[name='news_content']").val(value);
                var arr = $("#frmObjects").serializeObject();
                $.post(url_ashx, { add_news: window.escape(arr) }, function (data) {
                    alert(data);
                    window.location = "/admin/news/list";
                });
            }
        });
    </script>
</asp:Content>
